#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<ostream>
using namespace std;


class Solution{
    public:

    int ans1(string s){
        stack<int> stk;
        int len = s.size();
        int sign = 1;
        stk.push(sign);
        int ret = 0;
        int i = 0;
        
        while(i < len){
            if(s[i] == ' '){
                i++;
            }
            else if(s[i] == '+'){
                sign = stk.top();
                i++;
            }
            else if(s[i] == '-'){
                sign = -stk.top();
                i++;
            }
            else if(s[i] == '('){
                stk.push(sign);
                i++;
            }
            else if(s[i] == ')'){
                stk.pop();
                i++;
            }
            else{
                int num = 0;
                while(i < len && s[i] >= '0' && s[i] <= '9'){
                    num = num * 10 + s[i] - '0';
                    i++;
                }
                ret = ret + sign * num;
            }
        }

        return ret;
    }
};

void test1(){
    Solution s;
    string str = "(1+(4+5+2)-3)+(6+8)";
    int ret = s.ans1(str);
    cout << ret << endl;
}


int main(void){
    test1();

    return 0;
}